package com.han.demo.springbootmodulelistener;

import lombok.extern.slf4j.Slf4j;

/**
 * @author hanjl
 * @Description 监听器：文件读写的监听器实现类。泛型表明对MyFileEvent感兴趣
 * @ClassName MyFileListener
 * @createTime 2021/11/17 17:48
 */
@Slf4j
public class MyFileListener implements IMyApplicationListener<MyFileEvent> {

    /**
     * 文件读写的监听方法逻辑：进行进度条计算
     * @param event 监听的事件
     */
    @Override
    public void onMessage(MyFileEvent event) {
        log.info("监听器监听感兴趣的事件" +event.getClass().getName() + "被执行了。");
        int fileSize = event.getFileSize();
        int readSize = event.getReadSize();
        Double i = (double)(readSize * 100 / fileSize);
        log.info("springboot读取文件进度： "+ i + "%");
    }
}
